package shs;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import shs.bean.Cat;
import shs.bean.Dog;
import shs.bean.Pig;
import shs.bean.User;


@SpringBootApplication
//@SpringBootApplication(scanBasePackages = "") 指定扫包的路径
//@ComponentScan("") 指定扫包的路径

public class MyApplication {
    public static void main(String[] args) {
        //java10：局部变量类型的自动推断
        var ioc  = SpringApplication.run(MyApplication.class, args);
        //1.获取容器中所有组件的名字
        String[] names=ioc.getBeanDefinitionNames();
        //2.挨个遍历
        for (String name : names) {
           System.out.println("name:::"+name);
        }

        String[] forType = ioc.getBeanNamesForType(User.class);
        for (String s : forType) {
            System.out.println("s:::"+s);
        }
        //验证是不是单实例
        Object user1 = ioc.getBean("user01");
        Object user2 = ioc.getBean("user01");
        System.out.println(user1==user2);

        for (String s : ioc.getBeanNamesForType(Cat.class)) {
            System.out.println("cat:"+s);
        }
        for (String s : ioc.getBeanNamesForType(Dog.class)) {
            System.out.println("dog:"+s);
        }
        for (String s : ioc.getBeanNamesForType(User.class)) {
            System.out.println("user:"+s);
        }
        Pig pig = ioc.getBean(Pig.class);
        System.out.println(pig);
    }
}
